typedef struct MCache MCache;

enum
{
	MaxMCacheListLen = 256,		// Maximum objects on MCacheList
	MaxMCacheSize = 2<<20,		// Maximum bytes in one MCache
};

// Per-thread (in Go, per-M) cache for small objects.
// No locking needed because it is per-thread (per-M).
typedef struct MCacheList MCacheList;
struct MCacheList
{
	MLink *list;
	uint32 nlist;
	uint32 nlistmin;
};

struct MCache
{
	MCacheList list[NumSizeClasses];
	uint64 size;
	int64 local_cachealloc;	// bytes allocated (or freed) from cache since last lock of heap
	int64 local_objects;	// objects allocated (or freed) from cache since last lock of heap
	int64 local_alloc;	// bytes allocated (or freed) since last lock of heap
	int64 local_total_alloc;	// bytes allocated (even if freed) since last lock of heap
	int64 local_nmalloc;	// number of mallocs since last lock of heap
	int64 local_nfree;	// number of frees since last lock of heap
	int64 local_nlookup;	// number of pointer lookups since last lock of heap
	int32 next_sample;	// trigger heap sample after allocating this many bytes
	// Statistics about allocation size classes since last lock of heap
	struct {
		int64 nmalloc;
		int64 nfree;
	} local_by_size[NumSizeClasses];
};

void*	runtime_MCache_Alloc(MCache *c, int32 sizeclass, uintptr size, int32 zeroed);
void	runtime_MCache_Free(MCache *c, void *p, int32 sizeclass, uintptr size);
void	runtime_MCache_ReleaseAll(MCache *c);
